home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6980 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  67 lines

  1. Newsgroups: comp.lang.c++
  2. Path: tank.news.pipex.net!pipex!warwick!bsmail!talisker!nathan
  3. From: nathan@pact.srf.ac.uk (Nathan Sidwell)
  4. Subject: Re: Binary association problem
  5. Message-ID: <Dn2ppp.5nr@uns.bris.ac.uk>
  6. Sender: usenet@uns.bris.ac.uk (Usenet news owner)
  7. Nntp-Posting-Host: talisker.pact.srf.ac.uk
  8. Organization: Inmos
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. References: <31296F14.88E@esec.ch>
  11. Date: Tue, 20 Feb 1996 12:08:12 GMT
  12.  
  13. Oliver Plohmann (opl@esec.ch) wrote:
  14. : -------------------------a.h------------------------
  15.  
  16. : class B;
  17.  
  18. : class A {
  19.  
  20. :         int* x;
  21. : public:
  22.  
  23. :         A() {};
  24. :         ~A() {};
  25.  
  26. :         void operator+(const int& i) {
  27. :                 *x=i;   // protection violation !
  28. :         };
  29. : };
  30.  
  31. : -------------------------b.h------------------------
  32. : #include "a.h"
  33.  
  34. : class A;
  35.  
  36. : class B {
  37.  
  38. :         A* x;
  39. : public:
  40.  
  41. :         B() { *x=5; };
  42. :         ~B() {};
  43. : };
  44.  
  45. : --------------------------test.cpp--------------------
  46.  
  47. : #include "b.h"
  48.  
  49. : void main()
  50. : {
  51. :         B b;    // protection violation in A::operator=(const int& i)
  52. : }
  53.  
  54. What it looks like your doing is the equivalent of
  55.  
  56.     int *a;
  57.     *a = 5;
  58.  
  59. a has not been set, so the dereference invokes undefined behaviour.
  60.  
  61. nathan
  62. --
  63. Nathan Sidwell                         Holder of the Xmris home page
  64. Chameleon Architecture Group at SGS-Thomson, formerly Inmos
  65. http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
  66. nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
  67.